package com.crdeng.business.converter;

import com.crdeng.business.entity.Product;
import com.crdeng.business.vo.ProductVO;
import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 物资转换类
 */
public class ProductConverter {


    /**
     * 转VOList
     * @param list
     * @return
     */
    public static List<ProductVO> Converter2VOList(List<Product> list){
        List<ProductVO> productVOS = new ArrayList<>();
        if (!CollectionUtils.isEmpty(list)){
            for (Product product : list) {
                ProductVO productVO = converter2ProductVO(product);
                productVOS.add(productVO);
            }
        }
        return productVOS;

    }

    /**
     * 转VO
     * @param product
     * @return
     */
    public static ProductVO converter2ProductVO(Product product) {
        ProductVO productVO = new ProductVO();
        BeanUtils.copyProperties(product,productVO);
        return productVO;
    }

    public  static  List<ProductVO>  converter2CategoryKeys(List<ProductVO> productVOList){
        List<ProductVO> productVOS = new ArrayList<>();
        for (ProductVO productVO : productVOList) {
            Long [] category=new Long[3];
            category[0]=(productVO.getOneCategoryId());
            category[1]=(productVO.getTwoCategoryId());
            category[2]=(productVO.getThreeCategoryId());
            productVO.setCategoryKeys(category);
            productVOS.add(productVO);
        }
        return productVOS;
    }


}
